<?php 
//function cek_profpic($pic){
//    if($pic == null){
//        echo base_url('img/placeholder.png');
//    }else{
//        echo base_url('img/profpic/'.$pic);
//    }
//}

$this->load->model('model_comment');
$this->load->model('model_user');
$current = $this->model_user->curProfPic();
foreach($postings as $post) { 
?>
<li class="media">
    <a class="pull-left" href="#">
        <img class="media-object span1 img-polaroid" src="<?php cek_profpic($post->profpic); ?>">
    </a>
    <div class="media-body">
        <h4 class="media-heading" style="text-transform: capitalize;"><?php echo $post->nama; ?></h4>
        <?php echo $post->posting; ?>
        <br /><br />

        <!-- Nested media object -->
        <?php
        $comments = $this->model_comment->getComments($post->id_posting);
        if($comments){
            foreach($comments as $comment){
        ?>
        <div class="media">
            <a class="pull-left" href="#">
                <img class="media-object span1 img-licek" src="<?php cek_profpic($comment->profpic); ?>">
            </a>
            <div class="media-body">
                <h4 class="media-heading"><?php echo $comment->nama; ?></h4>
                <?php echo $comment->comment; ?>
            </div>
        </div>
        <?php 
        }
        }else{
        ?>
        <div class="media">
            <div class="media-body">
                <h4 class="media-heading">No comment yet.</h4>
            </div>
        </div>
        <?php } ?>
        <div class="media">
            <a class="pull-left" href="#">
                <img class="media-object span1 img-licek" src="<?php cek_profpic($current->profpic); ?>">
            </a>
            <div class="media-body">
                <form action="#" name="commentForm">
                    <input type="hidden" class="id_posting" value="<?php echo $post->id_posting; ?>"/>
                    <textarea name="comment" class="span5 comment"></textarea>
                    <input type="submit" value="Comment" class="btn btn-primary"/>
                </form>
            </div>
        </div>
    </div>
</li>
<?php } ?>
<script type="text/javascript">
    $('form[name="commentForm"]').live('submit', function () {
        id_user = '<?php echo $this->session->userdata('id_user'); ?>';
        id_posting = $(this).find('.id_posting').val();
        comment = $(this).find('.comment').val();
        $.post("<?php echo site_url('dosen/comment'); ?>", { id_user:id_user, id_posting:id_posting, comment: comment });
        comment = '';
        location.reload();
    });
</script>